package ListNode;
// 2-两数相加-middle
// meth: 取对应位置val相加，保存进位carry
// 取值：int x = (l1 == null) ? 0 : l1.val;
// 进位：carry = val / 10;
// 赋值：cur.next = new ListNode(val % 10);
// 更新节点：if(l1 != null) l1 = l1.next;

import java.util.Scanner;

public class AddTwoNumbers {
    public static class ListNode{
        int val;
        ListNode next;
        ListNode(){}
        ListNode(int val){
            this.val = val;
        }
        ListNode(int val, ListNode next){
            this.val = val;
            this.next = next;
        }
    }
    public static ListNode addTwoNumbers(ListNode l1, ListNode l2){
        ListNode dummy = new ListNode(-1);
        ListNode cur = dummy;
        // 进位
        int carry = 0;
        while(l1 != null || l2 != null){
            // 取值
            int x = (l1 != null) ? l1.val : 0;
            int y = (l2 != null) ? l2.val : 0;
            // 计算结果
            int val = x + y + carry;
            // 更新进位
            carry = val / 10;
            // 创建节点
            cur.next = new ListNode(val % 10);
            // 更新l1, l2, cur
            if(l1 != null) l1 = l1.next;
            if(l2 != null) l2 = l2.next;
            cur = cur.next;
        }
        // 最后一位发生进位
        if(carry == 1) cur.next = new ListNode(carry);
        return dummy.next;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s1 = sc.nextLine().split(",");
        String[] s2 = sc.nextLine().split(",");
        ListNode l1 = new ListNode(Integer.parseInt(s1[0]));
        ListNode cur = l1;
        for(int i = 1; i < s1.length; i++){
            cur.next = new ListNode(Integer.parseInt(s1[i]));
            cur = cur.next;    
        }
        ListNode l2 = new ListNode(Integer.parseInt(s2[0]));
        cur = l2;
        for(int i = 1; i < s2.length; i++){
            cur.next = new ListNode(Integer.parseInt(s2[i]));
            cur = cur.next;    
        }
        ListNode res = addTwoNumbers(l1, l2);
        while(res != null){
            System.out.print(res.val + " -> ");
            res = res.next;
        }
        sc.close();
    }
}
